package io.geely.push.modules.push.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.geely.push.common.utils.PageUtils;
import io.geely.push.common.utils.R;
import io.geely.push.common.validator.ValidatorUtils;
import io.geely.push.modules.push.entity.PushdataEntity;
import io.geely.push.modules.push.service.PushdataService;
/**
 * 
 *
 * @author qianjiang
 * @email qianjiang@geely.com
 * @date 2018-12-07 15:22:27
 */
@RestController
@RequestMapping("sys/pushdata")
public class PushdataController {
    @Autowired
    private PushdataService pushdataService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:pushdata:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = pushdataService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:pushdata:info")
    public R info(@PathVariable("id") Long id){
        PushdataEntity pushdata = pushdataService.selectById(id);

        return R.ok().put("pushdata", pushdata);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:pushdata:save")
    public R save(@RequestBody PushdataEntity pushdata){
        pushdataService.insert(pushdata);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:pushdata:update")
    public R update(@RequestBody PushdataEntity pushdata){
        ValidatorUtils.validateEntity(pushdata);
        pushdataService.updateAllColumnById(pushdata);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:pushdata:delete")
    public R delete(@RequestBody Long[] ids){
        pushdataService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }

}
